﻿using Daemon.Data.Infrastructure.Auth;
using Daemon.Middleware;
using Daemon.Model;
using Daemon.Repository.Contract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DaemonAPI.Helpers
{
	public class MFAHelper
	{
		internal static bool IsEnableEmailAuth(BaseAuthUser user)
		{
			var clientConfigRepository = ServiceLocator.Resolve<IClientConfigRepository>();
			var clientConfig = clientConfigRepository.Find();

			if (clientConfig.EnableMultifactorAuth
				&& clientConfig.AllowMultifactorAuthEmail
				&& user.UserRoles != null && user.UserRoles.Any(r => r.AdminRole.EnableMultifactorAuth)
				&& !string.IsNullOrEmpty(user.Email))
			{
				return true;
			}

			return false;
		}
	}
}
